home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6825 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  96 lines

  1. Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++
  2. Path: alexandria.organon.com!alexandria!jsa
  3. From: jsa@organon.com (Jon S Anthony)
  4. Subject: Re: C/C++ knocks the crap out of Ada
  5. In-Reply-To: ok@goanna.cs.rmit.EDU.AU's message of 19 Feb 1996 17:43:31 +1100
  6. Message-ID: <JSA.96Feb19192415@organon.com>
  7. Sender: news@organon.com (news)
  8. Organization: Organon Motives, Inc.
  9. References: <00001a73+00002504@msn.com> <4etcmm$lpd@nova.dimensional.com>
  10.     <3114d8fb.5a455349@zesi.ruhr.de> <4f5h5t$f13@vixen.cso.uiuc.edu>
  11.     <4g1bgf$l5@mailhub.scitec.com.au> <312515DF.7D3B@cmlj.demon.co.uk>
  12.     <4g5sas$787@goanna.cs.rmit.EDU.AU> <4g966j$cr8@goanna.cs.rmit.EDU.AU>
  13. Date: Tue, 20 Feb 1996 00:24:15 GMT
  14.  
  15. In article <4g966j$cr8@goanna.cs.rmit.EDU.AU> ok@goanna.cs.rmit.EDU.AU (Richard A. O'Keefe) writes:
  16.  
  17. > Simple I/O:
  18. > Step 1
  19. >     Look it up in the manual
  20. > Step 2
  21. >     Do what the Fine Manual says.
  22. > *SIMPLE* I/O involves withing and using a couple of standard packages,
  23. > and then using Put, New_Line, Get, and Skip_Line.  Pretty darned simple.
  24. > It has not been a problem for first-year students at this university.
  25. > Ada does not support Fortran-style formatted I/O, nor PL/I style
  26. > formatted or pictured I/O (but see Interfaces.COBOL).
  27.  
  28. For most naive (first time users) needs it is even simpler than this.
  29. Here, again, is a version in C and Ada of a simple first program:
  30.  
  31. First, the Ada (14 lines):
  32.  
  33. with Ada.Command_Line;  use Ada.Command_Line;
  34. with Text_Io;  use Text_Io;
  35.  
  36. procedure X is
  37.  
  38. begin
  39.     Put_Line(
  40.         "My name is " & Command_Name & ", I have" &
  41.         Integer'Image(Argument_Count) & " arguments.");
  42.     Put_Line("They are: ");
  43.     for I in 1..Argument_Count loop
  44.         Put_Line("  " & Argument(I));
  45.     end loop;
  46. end;
  47.  
  48. $ gnatmake $tests_wrk/x.adb
  49. $ x 1 2 3
  50. My name is x, I have 3 arguments.
  51. They are: 
  52.   1
  53.   2
  54.   3
  55.  
  56.  
  57. Now the C (14 lines):
  58.  
  59. #include <stdio.h>
  60.  
  61. main (argc, argv)
  62.     int argc;
  63.     char *argv[];
  64.  
  65. {
  66.     int i;
  67.  
  68.     printf ("My name is %s, I have %d arguments \n", argv[0], argc-1);
  69.     printf ("They are: \n");
  70.     for (i = 1; i < argc; i++)
  71.     printf("  %s\n", argv[i]);
  72. }
  73.  
  74. $ gcc -o cx cx.c
  75. $ cx 1 2 3
  76. My name is cx, I have 3 arguments 
  77. They are: 
  78.   1
  79.   2
  80.   3
  81.  
  82.  
  83. /Jon
  84. -- 
  85. Jon Anthony
  86. Organon Motives, Inc.
  87. 1 Williston Road, Suite 4
  88. Belmont, MA 02178
  89.  
  90. 617.484.3383
  91. jsa@organon.com
  92.  
  93.